package com.mauth.common.encoder;


import com.mauth.common.utils.AESUtil;
import lombok.SneakyThrows;
import org.springframework.security.crypto.password.PasswordEncoder;

public class AesPasswordEncoder implements PasswordEncoder {
    private String aesSecret;

    public AesPasswordEncoder() {
    }

    public AesPasswordEncoder(String aesSecret) {
        this.aesSecret = aesSecret;
    }

    @SneakyThrows
    @Override
    public String encode(CharSequence rawPassword) {
        return AESUtil.encrypt(String.valueOf(rawPassword), aesSecret);

    }

    @SneakyThrows
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encode(rawPassword).equals(encodedPassword);
    }

    @Override
    public boolean upgradeEncoding(String encodedPassword) {
        return false;
    }

}
